// proxyCenter.js
const app = getApp()
var util = require("../../utils/util.js")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    swiperbox: app.globalData.swiperbox,
    swiper: app.globalData.swiper,

    balance:'0.0',
    commission:0,
    todayAmount:'0',
    todayTime:"--:--",
    timePre:'',
    grid: [
      {
        name:'收益总计',
        txt:'¥0'
      }, {
        name: '设备总数',
        txt: '0'
      }, {
        name: '我的店铺',
        txt: '0'
      },
    ],

    memu:[
      {
        title: '店铺管理',
        label:'添加店铺商家',
        url: '../../pages/proxySubShopManage/proxySubShopManage'
      }, {
        title: '设备管理',
        label: '所有设备展示',
        url: '../../pages/proxyDevice/proxyDevice'
      }, {
        title: '人员管理',
        label: '安装业务授权',
        url: '../../pages/proxySerive/proxySerive'
      }, {
        title: '收入统计',
        label: '收益记录明细',
        url: '../../pages/proxyIncome/proxyIncome?userType=agent'
      }, {
        title: '使用分析',
        label: '设备使用信息',
        url: '../../pages/proxyUsageRate/proxyUsageRate'
      }
    ]
  },

  
  withdraw:function(){
    var balance = this.data.balance;
    wx.navigateTo({
      url: '../../pages/proxyWithdraw/proxyWithdraw?balance=' + balance,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var date = util.formatTime(new Date);
    var timePre = Number(date.substring(11, 13) * 60) + Number(date.substring(14, 16))
    that.setData({
      userInfo: app.globalData.userInfo,
      swiper: wx.getStorageSync('swiper') || app.globalData.swiper,
      todayTime:date.substring(11, 16),
      timePre: timePre
    })
    var data = {};
    app.post("agent/agentIndex",data).then((res) =>{
      if (res.code == 200) {
        var data = res.data;
        var deviceCount = 'grid[1].txt';
        var shopCount = 'grid[2].txt';
        var cumulative = 'grid[0].txt'
        that.setData({
          [deviceCount]: data.deviceCount,
          [shopCount]: data.shopCount,
          todayAmount: data.todayAmount,
          [cumulative]: '￥'+data.account.cumulative,
          balance: data.account.balance,
          commission: data.agent.commission
        })
        app.globalData.agentRate = data.agent.commission ? data.agent.commission : '-'
      }
    }).catch((errMsg) =>{
      console.log(errMsg);//错误提示信息
    })
  }
})